<template>
  <div>
    <!-- 3.导航 -->
    <div class="navs">
      <span
        v-for="(item,index) in nav"
        :key="item"
        :class="index==n?'select':''"
        @click="n=index"
      >{{item}}</span>
    </div>
    <!-- 5.展示列表 -->
    <div v-if="arr.length>0">
      <div class="item" @click="$router.push('/detail/'+item.id)" v-for="item in arr[n].content" :key="item.id">
        <img class="img" :src="$pre+item.img" alt />
        <div class="right">
            <h3>{{item.goodsname}}</h3>
            <div>现价格:￥{{item.price}}</div>
        </div>
        
      </div>
    </div>
  </div>
</template>

<script>
import { reqHomeGoods } from "../../../http/api";
export default {
  data() {
    return {
      // 1.导航数据
      nav: ["热门推荐", "上新推荐", "所有商品"],
      n: 0,
      // 2.初始化数据
      arr: [],
    };
  },
  mounted() {
    // 4.请数据
    reqHomeGoods().then((res) => {
      this.arr = res.data.list;
    });
  },
};
</script>

<style scoped>
.navs {
  display: flex;
}
.navs span {
  flex: 1;
  text-align: center;
  line-height: 0.6rem;
  display:block;
  margin-top:0.2rem;
}
.navs .select {
  background:rgb(247, 100, 3);
  color:white;
}
.item {
  margin: 0.2rem;
  background: white;
  border:1px solid black;
  width: 6.5rem;
  height: 3rem;
  overflow: hidden;
  
}
.img {
  width: 2rem;
  height: 2.5rem;
  float: left;
  margin-top:0.2rem;
}
.right{
    float:left;
    margin-top:0.2rem;

}
.right div{
    color:red;
}
</style>